/*****************************************************************************************
Arise Engine		SplitterWnd.cpp

					E-mail:		arise_engine@mail.ru

created:			18.03.2007
last changes:		18.03.2007
*****************************************************************************************/
#include "stdafx.h"


void CMySplitterWnd::ActivateNext(BOOL bPrev)
{
    ASSERT_VALID(this);

    // find the coordinate of the current pane
    int row, col;
    if (GetActivePane(&row, &col) == NULL)
    {
        TRACE0("Warning: Cannot go to next pane - there is no current view.\n");
        return;
    }
    ASSERT(row >= 0 && row < m_nRows);
    ASSERT(col >= 0 && col < m_nCols);

    // determine next pane
    if (bPrev)
    {
        // prev
        if (--col < 0)
        {
            col = m_nCols - 1;
            if (--row < 0)
            {
                if( m_pSplitterWndPrev != NULL )
                {                               
                    row = m_pSplitterWndPrev->GetRowCount() - 1;
                    col = m_pSplitterWndPrev->GetColumnCount() - 1;
                    m_pSplitterWndPrev->SetActivePane(row, col);
                    CWnd* pWnd = m_pSplitterWndPrev->GetActivePane();
                    //if( pWnd->IsKindOf( RUNTIME_CLASS( RenderView ) ) )
                    //    m_pSplitterWndPrev->ActivateNext( bPrev );
                    return;
                }
                row = m_nRows - 1;
            }
        }
    }
    else
    {
        // next
        if (++col >= m_nCols)
        {
            col = 0;
            if (++row >= m_nRows) 
            {
                if( m_pSplitterWndNext != NULL )
                {
                    m_pSplitterWndNext->SetActivePane(0, 0);
                    CWnd* pWnd = m_pSplitterWndPrev->GetActivePane();
                    //if( pWnd->IsKindOf( RUNTIME_CLASS( RenderView ) ) )
                    //    m_pSplitterWndPrev->ActivateNext( bPrev );
                    return;
                }
                row = 0;
            }
        }
    }

    // set newly active pane
    SetActivePane(row, col);
    CWnd* pWnd = GetActivePane();
    //if( pWnd->IsKindOf( RUNTIME_CLASS( RenderView ) ) )
    //    ActivateNext( bPrev );
}


void CMySplitterWnd::StopTracking(BOOL bAccept)
{
    m_bPreserveLastPaneSize = false;
    CSplitterWnd::StopTracking(bAccept);
}


void CMySplitterWnd::RecalcLayout()
{
    CRect rectClient;
    GetClientRect(rectClient);
    rectClient.InflateRect(-m_cxBorder, -m_cyBorder);

    if( m_nCols > 1 )
    {
        // It's the horizontal splitter
    }
    else
    {
        // It's one of the vertical splitters
        if( m_bPreserveLastPaneSize )
        {
            // Try to preserve the last row's current size
            int nLastCurSize = m_pRowInfo[m_nRows - 1].nCurSize;
            if( nLastCurSize != -1 )
            {
                if( rectClient.Height() - nLastCurSize - m_cySplitter > m_pRowInfo[0].nMinSize )
                    m_pRowInfo[0].nIdealSize = rectClient.Height() - nLastCurSize - m_cySplitter;
            }
            m_bPreserveLastPaneSize = false;
        }
    }
    
    CSplitterWnd::RecalcLayout();
}

